home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / aessrc12 / aescomn.s < prev    next >
Text File  |  1990-11-23  |  5KB  |  103 lines

  1.  
  2. ;*========================================================================
  3. ;*
  4. ;* AESFAST Public Domain GEM bindings.
  5. ;*
  6. ;*  04/06/89    v1.2
  7. ;*              Added TST.W just before RTS in aes_return routine.  This
  8. ;*              hack keeps Laser C happy.  Laser has an optimization such
  9. ;*              that source code such as:
  10. ;*                 if (!rsrc_load(filename))
  11. ;*                      form_error(errno);
  12. ;*              Will generate assembler code like:
  13. ;*                 jsr   _rsrc_load
  14. ;*                 bne   ...
  15. ;*              So we have to make sure the CCR flags match the values in
  16. ;*              d0 upon return.  Returns through aes_do were working fine,
  17. ;*              but the extra tst instruction was needed in aes_return.
  18. ;*========================================================================
  19.  
  20. ;*************************************************************************
  21. ;*
  22. ;* AESCOMN - Common routines (takes the place of CRYSTAL).
  23. ;*
  24. ;*************************************************************************
  25.  
  26. AES_ALLOCBSS = 1                        ; Set flag to alloc BSS in sh file.
  27.  
  28.           .include  "aesfast.sh"
  29.  
  30.           .text
  31.  
  32. ;-------------------------------------------------------------------------
  33. ; aes_do - Set up AESBLOCK, call trap 2, return directly to caller in
  34. ;          program (do not go back to binding routine).
  35. ;
  36. ;          This routine is entered via 'jmp'.
  37. ;-------------------------------------------------------------------------
  38.  
  39. aes_do:  
  40.           subq.l    #2,sp               ; Allocate intout[1].
  41.           move.l    a0,d1               ; save adrin pointer
  42.           lea       aesblock,a0         ; Load pointer to AES block, 
  43.           movep.l   d0,control+1(a0)    ; fill in the control array (!),
  44.           move.l    a1,pintin(a0)       ; store the intin ptr into aespb
  45.           move.l    d1,padrin(a0)       ; store the adrin ptr into aespb
  46.           move.l    sp,pintout(a0)      ; store the intout ptr into aespb
  47.           move.l    a0,d1               ; move the aespb pointer to the
  48.           move.w    #$C8,d0             ; interface register, also the AES
  49.           trap      #2                  ; function code, call AES.
  50.           move.w    (sp)+,d0            ; Return to caller with value from
  51.           rts                           ; intout[0] in d0 (& CCR matches d0).
  52.           
  53. ;-------------------------------------------------------------------------
  54. ; aes_return - Return values from the intout array (on the stack) to
  55. ;              the variables the caller gaves us pointers to, then 
  56. ;              return directly to the caller of the binding.
  57. ;
  58. ;              This routine is entered via 'jmp'.
  59. ;-------------------------------------------------------------------------
  60.  
  61. aes_return:
  62.           move.w    0(a6,d1.w),d0       ; 1st...intout[0] always goes to d0.
  63. .ret_loop:
  64.           addq.w    #2,d1               ; Increment intout offset,
  65.           beq.s     .alldone            ; if zero, all return values done.
  66.           move.l    (a1)+,a0            ; Get pointer to return variable,
  67.           move.w    0(a6,d1.w),(a0)     ; move value from intout[n] to
  68.           bra.s     .ret_loop           ; variable pointed to by call parms.
  69. .alldone:
  70.           unlk      a6                  ; Undo the stack, & return intout[0]
  71.           tst.w     d0                  ; (insure CCR matches intout[0]) to
  72.           rts                           ; caller of the original binding.
  73.  
  74. ;-------------------------------------------------------------------------
  75. ; AES call - Set up AESBLOCK, call trap 2, return to binding routine that
  76. ;            called us.  That binding routine will probably do some little
  77. ;            cleanup or something, then want to exit via aes_return, above.
  78. ;            On exit from this routine, we will return a pointer to the
  79. ;            aes_return routine in a0, allowing the binding to do its thing
  80. ;            then get out via 'jmp (a0)', saving the need for a relocatable
  81. ;            reference to aes_return in the bindings.
  82. ;
  83. ;            This routine is entered via 'jsr'.
  84. ;-------------------------------------------------------------------------
  85.  
  86. aes_call:
  87.           move.l    a0,d1               ; save adrin pointer
  88.           lea       aesblock,a0         ; Load pointer to AES block, 
  89.           movep.l   d0,control+1(a0)    ; fill in the control array (!),
  90.           move.l    a1,pintin(a0)       ; store the intin ptr into aespb
  91.           move.l    d1,padrin(a0)       ; store the adrin ptr into aespb
  92.           add.l     a6,d2               ; build the intout ptr
  93.           move.l    d2,pintout(a0)      ; store it into aespb
  94.           move.l    a0,d1               ; move the aespb pointer to the
  95.           move.w    #$C8,d0             ; interface register, also the AES
  96.           trap      #2                  ; function code, call AES, return
  97.           lea       aes_return(pc),a0   ; a pointer to the return routine
  98.           rts                           ; to the calling binding routine.
  99.  
  100.  
  101. ;         end of code
  102.  
  103.